package org.taskmanager.dao;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;
import org.taskmanager.entity.Task;

@Repository("taskDao")
public class TaskDAOJPA implements TaskDAO {

	@PersistenceContext
	private EntityManager entityManager;

	@Override
	public void persist(Task task) {
		entityManager.persist(task);
		entityManager.flush();
	}

	@Override
	public void update(Task task) {
		entityManager.merge(task);
	}

	@Override
	public void delete(Task task) {
		entityManager.remove(task);
	}

	@Override
	public Task getTaskById(Long id) {
		return entityManager.find(Task.class, id);
	}

}
